# CMakeLists.txt

# This is the LGPL libmariadb project.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
INCLUDE(CheckFunctionExists)
IF(COMMAND CMAKE_POLICY)
  SET(NEW_POLICIES CMP0003 CMP0022 CMP0023)
  FOREACH(TYPE OLD NEW)
    FOREACH(P ${${TYPE}_POLICIES})
      IF(POLICY ${P})
        CMAKE_POLICY(SET ${P} ${TYPE})
      ENDIF()
    ENDFOREACH()
  ENDFOREACH()
ENDIF()


PROJECT(mariadb-connector-c C)

# Is C/C built as subproject?
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)

# do not inherit include directories from the parent project
SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS
    WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL
    INSTALL_LAYOUT WITH_TEST_SRCPKG)
  SET(${V} ${${OPT}${V}})
ENDFOREACH()

#SET(PACKAGE_STATUS_SUFFIX "beta")

SET(CC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

SET(CPACK_PACKAGE_VERSION_MAJOR 3)
SET(CPACK_PACKAGE_VERSION_MINOR 1)
SET(CPACK_PACKAGE_VERSION_PATCH 0)
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 +
                            ${CPACK_PACKAGE_VERSION_MINOR} * 100   +
                            ${CPACK_PACKAGE_VERSION_PATCH}")

MACRO(ADD_OPTION _name _text _default)
  IF(NOT DEFINED ${_name})
    SET(${_name} ${_default})
  ENDIF()
  OPTION(${OPT}${_name} "${_text}" "${${_name}}")
ENDMACRO()

### Options ###
IF(NOT WIN32)
  ADD_OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" OFF)
ELSE()
  ADD_OPTION(WITH_MSI "Build MSI installation package" OFF)
  ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF)
  ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF)
ENDIF()

ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON)
ADD_OPTION(WITH_DYNCOL "Enables support of dynamic coluumns" ON)
ADD_OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" ON)
ADD_OPTION(WITH_CURL "Enables use of curl" ON)
ADD_OPTION(WITH_SSL "Enables use of TLS/SSL library" ON)
###############

INCLUDE(${CC_SOURCE_DIR}/cmake/misc.cmake)

IF(WITH_SIGNCODE)
  IF(WIN32 AND NOT SIGN_OPTIONS)
    SET(SIGN_OPTIONS /a /t http://timestamp.verisign.com/scripts/timstamp.dll)
  ELSE()
    SEPARATE_ARGUMENTS(SIGN_OPTIONS)
  ENDIF()
  MARK_AS_ADVANCED(SIGN_OPTIONS)
ENDIF()

SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2017 MariaDB Corporation Ab")

IF(WITH_RTC)
  SET(RTC_OPTIONS "/RTC1 /RTCc")
ENDIF()

IF(NOT WIN32)
  INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake)
  IF(GSSAPI_FOUND)
    INCLUDE_DIRECTORIES(${GSSAPI_INCS})
  ENDIF()
ENDIF()

INCLUDE(${CC_SOURCE_DIR}/cmake/plugins.cmake)

IF(AUTH_GSSAPI_PLUGIN_TYPE MATCHES "STATIC")
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${GSSAPI_LIBS})
ENDIF()


IF(WIN32)
  FILE(REMOVE ${CC_BINARY_DIR}/win/packaging/plugin.conf)
  INCLUDE(${CC_SOURCE_DIR}/cmake/version_info.cmake)
ENDIF()

IF(NOT IS_SUBPROJECT)
IF(MSVC)
  # Speedup system tests
  INCLUDE(${CC_SOURCE_DIR}/cmake/WindowsCache.cmake)
  IF (MSVC)
    SET(CONFIG_TYPES "DEBUG" "RELEASE" "RELWITHDEBINFO")
    FOREACH(BUILD_TYPE ${CONFIG_TYPES})
      FOREACH(COMPILER CXX C)
        SET(COMPILER_FLAGS "${CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}}")
        IF (NOT COMPILER_FLAGS STREQUAL "")
          STRING(REPLACE "/MD" "/MT" COMPILER_FLAGS ${COMPILER_FLAGS})
          SET(COMPILER_FLAGS "${COMPILER_FLAGS} -WX")
          IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
            SET(COMPILER_FLAGS "${COMPILER_FLAGS} ${RTC_OPTIONS}")
            STRING(REPLACE "/Zi" "/ZI" COMPILER_FLAGS ${COMPILER_FLAGS})
          ELSE()
            STRING(REPLACE "/Zi" "/Z7" COMPILER_FLAGS ${COMPILER_FLAGS})
          ENDIF()
          MESSAGE (STATUS "CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}= ${COMPILER_FLAGS}")
          SET(CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE} ${COMPILER_FLAGS})
        ENDIF()
      ENDFOREACH()
    ENDFOREACH()
  ENDIF()
ENDIF()
ENDIF(NOT IS_SUBPROJECT)

# Disable dbug information for release builds
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")

IF(CMAKE_COMPILER_IS_GNUCC)
  INCLUDE(CheckCCompilerFlag)
  SET(GCC_FLAGS -Wunused -Werror -Wlogical-op -Wno-uninitialized  -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -fno-builtin -Wno-undef)
  FOREACH(GCC_FLAG ${GCC_FLAGS})
    string(REPLACE "-" "" FLAG_NO_HYPHEN ${GCC_FLAG})
    CHECK_C_COMPILER_FLAG("${GCC_FLAG}" OK_${FLAG_NO_HYPHEN})
    IF(${OK_${FLAG_NO_HYPHEN}})
      SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_FLAG}")
    ENDIF()
  ENDFOREACH()
ENDIF()

# If the build type isn't specified, set to Relwithdebinfo as default.
IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
ENDIF()

# various defines for generating include/mysql_version.h
INCLUDE(FindGit)
IF(GIT_EXECUTABLE)
  EXECUTE_PROCESS(
    COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
      WORKING_DIRECTORY ${CC_SOURCE_DIR}
       OUTPUT_VARIABLE OUT RESULT_VARIABLE RES)
   IF(RES EQUAL 0)
    STRING(REGEX REPLACE "\n$" "" CC_SOURCE_REVISION "${OUT}")
  ENDIF()
ENDIF()
SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd !

# if C/C is build as subproject inside MariaDB server tree we will
# use the version defined by server
IF(MAJOR_VERSION)
  SET(MARIADB_CLIENT_VERSION_MAJOR ${MAJOR_VERSION})
  SET(MARIADB_CLIENT_VERSION_MINOR ${MINOR_VERSION})
  SET(MARIADB_CLIENT_VERSION_PATCH ${PATCH_VERSION})
ELSE()
  SET(MARIADB_CLIENT_VERSION_MAJOR "10")
  SET(MARIADB_CLIENT_VERSION_MINOR "3")
  SET(MARIADB_CLIENT_VERSION_PATCH "6")
ENDIF()
SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}")
SET(MARIADB_BASE_VERSION "mariadb-${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}")
MATH(EXPR MARIADB_VERSION_ID "${MARIADB_CLIENT_VERSION_MAJOR} * 10000 +
                              ${MARIADB_CLIENT_VERSION_MINOR} * 100   +
                              ${MARIADB_CLIENT_VERSION_PATCH}")

IF (NOT MARIADB_PORT)
  SET(MARIADB_PORT 3306)
ENDIF ()
IF(NOT MARIADB_UNIX_ADDR)
  SET(MARIADB_UNIX_ADDR "/tmp/mysql.sock")
ENDIF()

INCLUDE("${CC_SOURCE_DIR}/cmake/install.cmake")
IF(NOT PLUGINDIR)
  SET(PLUGINDIR "${INSTALL_PLUGINDIR}")
ENDIF()

# todo: we don't character sets in share - all is compiled in
SET(SHAREDIR "share")
SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}")

INCLUDE(${CC_SOURCE_DIR}/cmake/SearchLibrary.cmake)

IF(WITH_EXTERNAL_ZLIB)
  FIND_PACKAGE(ZLIB)
  IF(ZLIB_FOUND)
    INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
    SET(LIBZ ${ZLIB_LIBRARY})
  ENDIF()
ENDIF()

IF(NOT WIN32)
  INCLUDE(TestBigEndian)
  TEST_BIG_ENDIAN(HAVE_BIGENDIAN)
ENDIF()

IF(UNIX)
  SEARCH_LIBRARY(LIBDL dlopen "dl")
  SEARCH_LIBRARY(LIBM floor m)
  SEARCH_LIBRARY(LIBPTHREAD pthread_getspecific "pthread;pthreads")
  SEARCH_LIBRARY(LIBNSL gethostbyname_r "nsl_r;nsl")
  SEARCH_LIBRARY(LIBSOCKET setsockopt socket)
  FIND_PACKAGE(Threads)
  SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ}
    ${LIBSOCKET} ${LIBDL} ${LIBM} ${LIBPTHREAD})
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ}
    ${LIBSOCKET} ${LIBDL} ${LIBM} ${LIBPTHREAD})
  #remove possible dups from required libraries
  LIST(LENGTH CMAKE_REQUIRED_LIBRARIES rllength)
  IF(${rllength} GREATER 0)
    LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
  ENDIF()
ENDIF()


IF(CMAKE_HAVE_PTHREAD_H)
  SET(CMAKE_REQUIRED_INCLUDES pthread.h)
ENDIF()

IF(DBUG_OFF)
  ADD_DEFINITIONS(-DDBUG_OFF=1)
ENDIF()

ADD_DEFINITIONS(-DMARIADB_SYSTEM_TYPE="${CMAKE_SYSTEM_NAME}")
ADD_DEFINITIONS(-DMARIADB_MACHINE_TYPE="${CMAKE_SYSTEM_PROCESSOR}")

IF(WIN32)
  SET(HAVE_THREADS 1)
  ADD_DEFINITIONS(-DHAVE_DLOPEN)
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
  IF(MSVC)
     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996" )
  ENDIF()
ELSEIF()
  SET(HAVE_THREADS ${CMAKE_USE_PTHREADS})
ENDIF()

# only let mariadb-config return the embedded server build flags
# if the library was actually built
IF(IS_SUBPROJECT AND WITH_EMBEDDED_SERVER)
  SET(EMBEDDED_STATUS "yes")
  ADD_DEFINITIONS(-DHAVE_EMBEDDED)
ENDIF()

# check for various include files
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckIncludeFiles.cmake)
# check for various functions
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckFunctions.cmake)
# check for various types
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckTypes.cmake)

IF(NOT DEFAULT_CHARSET)
  SET(DEFAULT_CHARSET "latin1")
ENDIF()


# convert SSL options to uppercase
IF(WITH_SSL)
  STRING(TOUPPER ${WITH_SSL} WITH_SSL)
ENDIF()
IF(WITH_SSL STREQUAL "ON")
  IF(WIN32)
    SET(WITH_SSL "SCHANNEL")
  ELSE()
    SET(WITH_SSL "OPENSSL")
  ENDIF()
ENDIF()

IF(NOT WITH_SSL STREQUAL "OFF")
  IF(WITH_SSL STREQUAL "OPENSSL")
    IF (NOT OPENSSL_FOUND)
      FIND_PACKAGE(OpenSSL)
    ENDIF()
    IF(OPENSSL_FOUND)
      ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/openssl.c")
      SET(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
      INCLUDE_DIRECTORIES(BEFORE ${OPENSSL_INCLUDE_DIR})

      TRY_RUN(LIBRESSL_RESULT HAVE_LIBRESSL
              ${CMAKE_BINARY_DIR}
              ${CC_SOURCE_DIR}/cmake/libressl_version.c
              COMPILE_DEFINITIONS "-I${OPENSSL_INCLUDE_DIR}"
              RUN_OUTPUT_VARIABLE LIBRESSL_VERSION)
      IF(HAVE_LIBRESSL)
        ADD_DEFINITIONS(-DHAVE_LIBRESSL)
        SET(TLS_LIBRARY_VERSION ${LIBRESSL_VERSION})
      ELSE()
        SET(TLS_LIBRARY_VERSION "OpenSSL ${OPENSSL_VERSION}")
      ENDIF()
    ELSE()
      MESSAGE1(TLS_LIBRARY_VERSION "OpenSSL/LibreSSL not found")
    ENDIF()
  ENDIF()
  IF(WITH_SSL STREQUAL "GNUTLS")
    FIND_PACKAGE(GnuTLS "3.3.24" REQUIRED)
    IF(GNUTLS_FOUND)
      ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/gnutls.c")
      SET(SSL_LIBRARIES ${GNUTLS_LIBRARY})
      SET(TLS_LIBRARY_VERSION "GnuTLS ${GNUTLS_VERSION_STRING}")
      INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
    ELSE()
      MESSAGE(FATAL_ERROR "GnuTLS not found")
    ENDIF()
  ENDIF()
  IF(WIN32)
    IF(WITH_SSL STREQUAL "SCHANNEL")
      ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS)
      SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/schannel.c"
                      "${CC_SOURCE_DIR}/libmariadb/secure/ma_schannel.c")
      INCLUDE_DIRECTORIES("${CC_SOURCE_DIR}/plugins/pvio/")
      SET(SSL_LIBRARIES secur32)
      SET(TLS_LIBRARY_VERSION "Schannel ${CMAKE_SYSTEM_VERSION}")
    ENDIF()
  ENDIF()
  MESSAGE1(TLS_LIBRARY_VERSION "TLS library/version: ${TLS_LIBRARY_VERSION}")

  MARK_AS_ADVANCED(SSL_SOURCES)
ENDIF()

IF(NOT WIN32)
  INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
ENDIF()

CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
               ${CC_BINARY_DIR}/include/ma_config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
               ${CC_BINARY_DIR}/include/config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/mariadb_version.h.in
               ${CC_BINARY_DIR}/include/mariadb_version.h)

INCLUDE_DIRECTORIES(${CC_BINARY_DIR}/include)

IF(WIN32)
  SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi crypt32)
ELSE()
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBPTHREAD} ${LIBDL} ${LIBM})
  IF(ICONV_EXTERNAL)
    SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${ICONV_LIBRARIES})
  ENDIF()
ENDIF()
IF(WITH_SSL)
  SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${SSL_LIBRARIES})
ENDIF()
MESSAGE1(SYSTEM_LIBS "SYSTEM_LIBS ${SYSTEM_LIBS}")
MARK_AS_ADVANCED(SYSTEM_LIBS)

IF(NOT REMOTEIO_PLUGIN_TYPE MATCHES "OFF")
  IF(CURL_FOUND)
    INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
    IF(REMOTEIO_PLUGIN_TYPE MATCHES "STATIC")
      SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${CURL_LIBRARIES})
    ENDIF()
    ADD_DEFINITIONS("-DHAVE_REMOTEIO=1")
  ENDIF()
ENDIF()
IF(NOT WIN32)
  IF(NOT AUTH_GSSAPI_PLUGIN_TYPE MATCHES "OFF")
    INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake)
    IF(GSSAPI_FOUND)
      INCLUDE_DIRECTORIES(${GSSAPI_INCS})
      IF(AUTH_GSSAPI_PLUGIN_TYPE MATCHES "STATIC")
        SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${GSSAPI_LIBS})
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
INCLUDE(${CC_SOURCE_DIR}/plugins/CMakeLists.txt)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(libmariadb)
IF(NOT WIN32)
  ADD_SUBDIRECTORY(mariadb_config)
ENDIF()

IF(IS_DIRECTORY ${CC_SOURCE_DIR}/unittest)
  IF(WITH_UNIT_TESTS)
    ADD_SUBDIRECTORY(unittest/mytap)
    ADD_SUBDIRECTORY(unittest/libmariadb)
  ENDIF()
ENDIF()

IF(CLIENT_DOCS)
  INSTALL(DIRECTORY ${CLIENT_DOCS}
          DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}}
          COMPONENT SharedLibraries)
ENDIF()


IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  ADD_SUBDIRECTORY(win/packaging)
ENDIF()
MESSAGE("SYSTEM processor: ${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers")
SET(CPACK_PACKAGE_NAME "mariadb_connector_c")
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
SET(CPACK_RESOURCE_FILE_LICENSE "${CC_SOURCE_DIR}/COPYING.LIB")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CC_SOURCE_DIR}/README.md")
INCLUDE(cmake/ConnectorName.cmake)
IF(NOT PACKAGE_STATUS_SUFFIX)
  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src")
  SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ELSE()
  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src")
  SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ENDIF()
# Build source packages
IF(GIT_BUILD_SRCPKG)
  # get branch name
  EXECUTE_PROCESS(COMMAND git show-branch OUTPUT_VARIABLE git_branch)
  STRING(REGEX MATCH "\\[([^]]+)\\]" git_branch ${git_branch})
  STRING(REGEX REPLACE "\\[|\\]" "" GIT_BRANCH ${git_branch})
  MESSAGE1(GIT_BRANCH "${GIT_BRANCH}")
  IF(WIN32)
    EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
  ELSE()
    EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
    EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=tar --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
    EXECUTE_PROCESS(COMMAND gzip -9 -f ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
  ENDIF()
ENDIF()

SET(CPACK_SOURCE_IGNORE_FILES
\\\\.git/
\\\\.gitignore
\\\\.gitattributes
CMakeCache\\\\.txt
cmake_dist\\\\.cmake
CPackConfig\\\\.cmake
mariadb_config\\\\.c$
\\\\.build/
html/
unittest
/cmake_install.cmake
/CTestTestfile.cmake
/CPackSourceConfig.cmake
/CMakeFiles/
/version_resources/
/_CPack_Packages/
\\\\.gz$
\\\\.zip$
mariadb_config/mariadb_config$
/CMakeFiles/
/version_resources/
/_CPack_Packages/
Makefile$
include/my_config\\\\.h$
)

IF(WITH_TEST_SRCPKG)
  SET(PACKAGE_FILE ${CC_SOURCE_DIR}/package.name)
  FILE(REMOVE ${PACKAGE_FILE})
  FILE(WRITE ${PACKAGE_FILE} ${CPACK_SOURCE_PACKAGE_FILE_NAME})
ENDIF()

IF(WIN32)
  SET(CPACK_GENERATOR "ZIP")
  SET(CPACK_SOURCE_GENERATOR "ZIP")
ELSE()
  SET(CPACK_GENERATOR "TGZ")
  SET(CPACK_SOURCE_GENERATOR "TGZ")
ENDIF()
INCLUDE(CPack)

IF(WITH_EXTERNAL_ZLIB)
  SET(zlib_status ${WITH_EXTERNAL_ZLIB})
ELSE()
  SET(zlib_status "yes (using bundled zlib)")
ENDIF()

MESSAGE1(STATUS "MariaDB Connector/c configuration:
-- Static PLUGINS ${PLUGINS_STATIC}
-- Dynamic PLUGINS ${PLUGINS_DYNAMIC}
-- CPack generation: ${CPACK_GENERATOR}
-- SSL support: ${WITH_SSL} Libs: ${SSL_LIBRARIES}
-- Zlib support: ${zlib_status}
-- Installation layout: ${INSTALL_LAYOUT}
-- Include files will be installed in ${INSTALL_INCLUDEDIR}
-- Libraries will be installed in ${INSTALL_LIBDIR}
-- Binaries will be installed in ${INSTALL_BINDIR}
-- Documentation included from ${CLIENT_DOCS}
-- Required: ${CMAKE_REQUIRED_LIBRARIES}
-- Embedded library config: ${EMBEDDED_STATUS}")
